﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;

namespace PRO_DOCS.DocumentManagementSystem.ADMIN.WIN.Configurations.Security
{
    public partial class ucDeniedUserRoles : ucBaseSecurity
    {

        public ucDeniedUserRoles()
        {
            InitializeComponent();

            try
            {
                PRO_DOCSDatabaseDataContext.proc_SYSTEM_ROLESLoadAll().ToList().ForEach(new Action<PRO_DOCS.DAL.Database.proc_SYSTEM_ROLESLoadAllResult>(delegate(PRO_DOCS.DAL.Database.proc_SYSTEM_ROLESLoadAllResult _systemRole)
                {
                    CheckedListBoxItem listViewItem = new CheckedListBoxItem();
                    listViewItem.Value = _systemRole.ROLE_ID.ToString();
                    listViewItem.Description = _systemRole.ROLE_NAME;
                    lstUserRoles.Items.Add(listViewItem);
                }));
            }
            catch { }
        }

        public void SAVE_DENIED_USER_ROLES(long archive_department_id, Guid _archive_department_folderstructure_id)
        {
            switch (CURRENT_SELECTED_SECURITY_OPTION)
            {
                case SecurityOptions.N_A:
                    break;
                #region DepartmentsSecurity
                    /*
                case SecurityOptions.DepartmentsSecurity:
                    {
                        //1. Delete old data
                        PRO_DOCSDatabaseDataContext.proc_ARCHIVE_DEPARTMENT_ROLESDeleteByARCHIVE_DEPARTMENT_ID(archive_department_id);
                        //2. save the new data
                        for (int i = 0; i < lstUserRoles.ItemCount; i++)
                        {
                            if (lstUserRoles.Items[i].CheckState.Equals(CheckState.Checked))
                            {
                                PRO_DOCSDatabaseDataContext.proc_ARCHIVE_DEPARTMENT_ROLESInsert(archive_department_id, Convert.ToInt64(lstUserRoles.Items[i].Value.ToString()));
                            }
                        }
                    }
                    break;
                    */
                #endregion
                case SecurityOptions.FolderStructureSecurity:
                    {
                        //1. Delete old data
                        PRO_DOCSDatabaseDataContext.proc_ARCHIVE_DEPARTMENTS_FOLDERS_STRUCTURE_DENIED_ROLESDeleteBy_FOLDERS_STRUCTURE_ID(_archive_department_folderstructure_id);
                        //2. save the new data
                        for (int i = 0; i < lstUserRoles.ItemCount; i++)
                        {
                            if (lstUserRoles.Items[i].CheckState.Equals(CheckState.Checked))
                            {
                                PRO_DOCSDatabaseDataContext.proc_ARCHIVE_DEPARTMENTS_FOLDERS_STRUCTURE_DENIED_ROLESInsert(_archive_department_folderstructure_id, Convert.ToInt64(lstUserRoles.Items[i].Value.ToString()));
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
        }

        public void LOAD_DENIED_USER_ROLES(SecurityOptions _securityOptions, long archive_department_id, Guid _archive_department_folderstructure_id)
        {
            lstUserRoles.UnCheckAll();
            CURRENT_SELECTED_SECURITY_OPTION = _securityOptions;
            switch (CURRENT_SELECTED_SECURITY_OPTION)
            {
                case SecurityOptions.N_A:
                    break;
                #region DepartmentsSecurity
                    /*
                case SecurityOptions.DepartmentsSecurity:
                    {
                        PRO_DOCSDatabaseDataContext.proc_ARCHIVE_DEPARTMENT_ROLESLoadAllByARCHIVE_DEPARTMENT_ID(archive_department_id).ToList().ForEach(new Action<PRO_DOCS.DAL.Database.proc_ARCHIVE_DEPARTMENT_ROLESLoadAllByARCHIVE_DEPARTMENT_IDResult>(delegate(PRO_DOCS.DAL.Database.proc_ARCHIVE_DEPARTMENT_ROLESLoadAllByARCHIVE_DEPARTMENT_IDResult _archive_department_role)
                        {
                            for (int i = 0; i < lstUserRoles.ItemCount; i++)
                            {
                                if (lstUserRoles.Items[i].Value.ToString().Equals(_archive_department_role.ROLE_ID.ToString()))
                                {
                                    lstUserRoles.SetItemChecked(i, true);
                                    break;
                                }
                            }
                        }));
                    }
                    break;
                     */
                #endregion

                case SecurityOptions.FolderStructureSecurity:
                    {
                        PRO_DOCSDatabaseDataContext.proc_ARCHIVE_DEPARTMENTS_FOLDERS_STRUCTURE_DENIED_ROLESLoadAllBy_FOLDERS_STRUCTURE_ID(_archive_department_folderstructure_id).ToList().ForEach(new Action<PRO_DOCS.DAL.Database.proc_ARCHIVE_DEPARTMENTS_FOLDERS_STRUCTURE_DENIED_ROLESLoadAllBy_FOLDERS_STRUCTURE_IDResult>(delegate(PRO_DOCS.DAL.Database.proc_ARCHIVE_DEPARTMENTS_FOLDERS_STRUCTURE_DENIED_ROLESLoadAllBy_FOLDERS_STRUCTURE_IDResult _folder_structure_denied_role)
                        {
                            for (int i = 0; i < lstUserRoles.ItemCount; i++)
                            {
                                if (lstUserRoles.Items[i].Value.ToString().Equals(_folder_structure_denied_role.ROLE_ID.ToString()))
                                {
                                    lstUserRoles.SetItemChecked(i, true);
                                    break;
                                }
                            }
                        }));
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
